package com.mi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mi.entity.ApplicationEntity;
import com.mi.entity.MyPages;
import com.mi.entity.RecruitEntity;
import com.mi.entity.UserEntity;
import com.mi.mapper.RecruitMapper;
import com.mi.service.RecruitService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class RecruitServiceImpl implements RecruitService {

    @Autowired(required = false)
    RecruitMapper recruitMapper;

    //根据条件查询招聘信息
    @Override
    public List<RecruitEntity> queryRecruits(RecruitEntity re) {
        return recruitMapper.queryRecruits(re);
    }

    @Override
    public RecruitEntity queryRecruitByid(int r_id) {
        return recruitMapper.queryRecruitByid(r_id);
    }

    //添加应聘信息
    @Override
    public boolean application(ApplicationEntity ae) {
        return recruitMapper.application(ae);
    }

    /**
     * 查询招聘信息
     * @param re
     * @return
     */
    public MyPages<RecruitEntity> queryRecruitss(RecruitEntity re){
        PageHelper.startPage(re.getPageNum(),re.getPageSize());
        List<RecruitEntity> userEntities = recruitMapper.queryRecruitss(re);
        PageInfo<RecruitEntity> pageInfo = new PageInfo<>(userEntities);
        MyPages<RecruitEntity> RecruitEntityMyPages = new MyPages<>();
        RecruitEntityMyPages.setList(pageInfo.getList());
        RecruitEntityMyPages.setPageNum(pageInfo.getPageNum());
        RecruitEntityMyPages.setPageSize(pageInfo.getPageSize());
        RecruitEntityMyPages.setPages(pageInfo.getPages());
        RecruitEntityMyPages.setPageCount((int)pageInfo.getTotal());
        return RecruitEntityMyPages;
    }

    /**
     * 查询单个招聘信息
     * @param re
     * @return
     */
    public RecruitEntity queryRecruit(RecruitEntity re){
        List<RecruitEntity> userEntities = recruitMapper.queryRecruitss(re);
        if (userEntities==null||userEntities.size()==0){
            return null;
        }
        return userEntities.get(0);
    }

    /**
     * 查询应聘信息
     * @param applicationEntity
     * @return
     */
    public MyPages<ApplicationEntity> queryApplications(ApplicationEntity applicationEntity){
        PageHelper.startPage(applicationEntity.getPageNum(),applicationEntity.getPageSize());
        List<ApplicationEntity> userEntities = recruitMapper.queryApplication(applicationEntity);
        PageInfo<ApplicationEntity> pageInfo = new PageInfo<>(userEntities);
        MyPages<ApplicationEntity> RecruitEntityMyPages = new MyPages<>();
        RecruitEntityMyPages.setList(pageInfo.getList());
        RecruitEntityMyPages.setPageNum(pageInfo.getPageNum());
        RecruitEntityMyPages.setPageSize(pageInfo.getPageSize());
        RecruitEntityMyPages.setPages(pageInfo.getPages());
        RecruitEntityMyPages.setPageCount((int)pageInfo.getTotal());
        return RecruitEntityMyPages;
    }

    /**
     * 查询单个应聘信息
     * @param applicationEntity
     * @return
     */
    public ApplicationEntity queryApplication(ApplicationEntity applicationEntity){
        List<ApplicationEntity> userEntities = recruitMapper.queryApplication(applicationEntity);
        if (userEntities==null||userEntities.size()==0){
            return null;
        }
        return userEntities.get(0);
    }

    /**
     * 更改状态
     * @param applicationEntity
     * @return
     */
    public boolean updApplicationStatus(ApplicationEntity applicationEntity){
        return recruitMapper.updApplicationStatus(applicationEntity);
    }

    /**
     * 删除应聘信息
     * @param ids
     * @return
     */
    public boolean delApplication(String[] ids){
        return recruitMapper.delApplication(ids);
    }

    /**
     * 更改状态
     * @param re
     * @return
     */
    public boolean updRecruitStatus(RecruitEntity re){
        return recruitMapper.updRecruitStatus(re);
    }

    /**
     * 删除招聘信息
     * @param ids
     * @return
     */
    public boolean delRecruit( String[] ids){
        return  recruitMapper.delRecruit(ids);
    }

    /**
     * 添加招聘信息
     * @param recruitEntity
     * @return
     */
    public boolean addRecruit(RecruitEntity recruitEntity){
        return recruitMapper.addRecruit(recruitEntity);
    }

    /**
     * 修改招聘信息
     * @param recruitEntity
     * @return
     */
    public boolean updRecruit(RecruitEntity recruitEntity){
        return recruitMapper.updRecruit(recruitEntity);
    }

    /**
     * 修改招聘信息
     * @param recruitEntity
     * @return
     */
    public boolean updRecruitNumber(RecruitEntity recruitEntity){
        return recruitMapper.updRecruitNumber(recruitEntity);
    }

}
